<?php

namespace app\api\controller\v38;

use app\api\controller\v2\Auth;
use app\common\cachemodel\ZlCouponActive;
use think\Exception;
use think\exception\PDOException;
use think\response\Json;

class IosActive extends Auth
{
    /**
     * 领取活动优惠券
     * @return Json
     * @throws Exception
     * @throws PDOException
     */
    public function getCoupon(): ?Json
    {
        if ($this->headers['app-type'] !== 'ios') {
            return show(config('code.error'), '服务异常，请稍后再试～');
        }

        $couponActiveModel = new ZlCouponActive();

        $res = $couponActiveModel->couponGiveActiv($this->user['id'], 28);

        if ($res) {
            return show(config('code.success'), '领取成功');
        }

        return show(config('code.error'), $couponActiveModel->errorMsg);
    }
}